from pydantic import BaseModel,field_serializer, ConfigDict, Field,Extra
from datetime import datetime,date
from typing import Optional, Dict, Any
import json


class UserBase(BaseModel):
    username: str = Field(default='', description="用户名称")

class UserCreate(UserBase):
    is_admin: Optional[int] = 1
    password: str = Field(..., description="密码")
    real_name:Optional[str]= Field(..., description="真名")
    status: Optional[int] = Field(default=1, description="状态")
    email: Optional[str] = Field(..., description="邮箱")
    phone: Optional[str] = Field(..., description="手机")
    gender: Optional[int] = Field(..., description="性别")
    birthday: Optional[datetime] = Field(..., description="生日")

    class Config:
        from_attributes = True

class UserInfo(UserBase):
    id: str = Field(..., description="用户ID")
    birthday: Optional[date] = Field(..., description="生日")
    email: Optional[str] = Field('', description="邮箱")
    phone: Optional[str] = Field('', description="手机")
    gender: Optional[int] = Field(1, description="性别")
    avatar: Optional[str] = Field('', description="头像")
    password: Optional[str] = Field('', description="密码")
    real_name: Optional[str] = Field('', description="真实名称")
    is_admin: Optional[int] = Field(0, description="是否管理员")
    remark: Optional[str] = Field('', description="备注")
    update_by: Optional[str] = Field('', description="更新人")
    updated_time: Optional[datetime] = Field(None, description="更新时间")
    deleted_at: Optional[datetime] = Field(None, description="删除时间")
    status: Optional[int] = 1

    # model_config = ConfigDict(from_attributes=True)
    # # orm_model=True 允许ORM模型转换
    model_config = ConfigDict(from_attributes=True,orm_model=True)


class findComment(BaseModel):
    id: int = Field(..., description="id")

    class Config:
        from_attributes = True

class userschema(UserBase):
    id: Optional[str] = None
    username: Optional[str] = None
    real_name: Optional[str] = None
    is_admin: Optional[str] = None
    create_time: Optional[datetime] = None
    email: Optional[str] = None
    phone: Optional[str] = None
    gender: Optional[int] = None
    birthday: Optional[datetime] = None
    status: Optional[str] = None
    pageIndex: int = 1
    pageSize: int = 10

    class Config:
        from_attributes = True